package com.zx.article.util;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileUploadException;

@WebServlet("/FileUploadServlet")
public class FileUploadServlet extends HttpServlet {

	private static final long serialVersionUID = -7680236706403091949L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		try {
//			请求内容剖析
			Map<String, Object> upload = Uploadfile.upload(request);
//			将上传内容写出
			new FmtRequest().write(response.getWriter(), upload);
		} catch (FileUploadException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
